<xsl:stylesheet version="1.1"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:math="http://exslt.org/math"
	xmlns="http://www.w3.org/2000/svg" 
	extension-element-prefixes="math">

	<xsl:param name="walk-body-front-skew-angle">0</xsl:param>
	<xsl:param name="walk-body-back-skew-angle">0</xsl:param>
	
	<xsl:param name="walk-arm-front-swing-angle">20</xsl:param>
	<xsl:param name="walk-arm-back-swing-angle">10</xsl:param>

	<xsl:param name="walk-forearm-front-swing-angle">60</xsl:param>
	<xsl:param name="walk-forearm-back-swing-angle">-10</xsl:param>

	<xsl:param name="walk-hip-front-swing-angle">20</xsl:param>
	<xsl:param name="walk-hip-back-swing-angle">20</xsl:param>

	<xsl:param name="walk-calf-front-swing-angle">-5</xsl:param>
	<xsl:param name="walk-calf-back-swing-angle">20</xsl:param>
	
	<xsl:template match="part[type//@name='humanoid-body']" mode="animate">
		<xsl:param name="state"/>
		<xsl:choose>
			<xsl:when test="$state='walking'">
				<animateTransform attributeName="transform"
					attributeType="XML" type="skewY" values="{$walk-body-front-skew-angle};{-$walk-body-back-skew-angle};{$walk-body-front-skew-angle}" keyTimes="0;0.5;1"
					begin="0s" dur="1s" fill="freeze" repeatCount="indefinite"/>		
							
			</xsl:when>
		</xsl:choose>	
	</xsl:template>
	
	<xsl:template match="part[@socket='left-shoulder' or @socket='right-shoulder']" mode="animate">
		<xsl:param name="state"/>
		
		
		<xsl:choose>
			<xsl:when test="$state='walking'">
				<xsl:variable name="values">
					<xsl:choose>
						<xsl:when test="@socket='left-shoulder'"><xsl:value-of select="-$walk-arm-front-swing-angle"/>;<xsl:value-of select="$walk-arm-back-swing-angle"/>;<xsl:value-of select="-$walk-arm-front-swing-angle"/></xsl:when>
						<xsl:otherwise><xsl:value-of select="$walk-arm-back-swing-angle"/>;<xsl:value-of select="-$walk-arm-front-swing-angle"/>;<xsl:value-of select="$walk-arm-back-swing-angle"/></xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<animateTransform attributeName="transform"
					attributeType="XML" type="rotate" values="{$values}" keyTimes="0;0.5;1"
					begin="0s" dur="1s" fill="freeze" repeatCount="indefinite"/>		
							
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="part[type//@name='humanoid-forearm']" mode="animate">
		<xsl:param name="state"/>
		
		
		<xsl:choose>
			<xsl:when test="$state='walking'">
				<xsl:variable name="values">
					<xsl:choose>
						<xsl:when test="../@socket='left-shoulder'"><xsl:value-of select="-$walk-forearm-front-swing-angle"/>;<xsl:value-of select="$walk-forearm-back-swing-angle"/>;<xsl:value-of select="-$walk-forearm-front-swing-angle"/></xsl:when>
						<xsl:otherwise><xsl:value-of select="$walk-forearm-back-swing-angle"/>;<xsl:value-of select="-$walk-forearm-front-swing-angle"/>;<xsl:value-of select="$walk-forearm-back-swing-angle"/></xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<animateTransform attributeName="transform"
					attributeType="XML" type="rotate" values="{$values}" keyTimes="0;0.5;1"
					begin="0s" dur="1s" fill="freeze" repeatCount="indefinite"/>		
							
			</xsl:when>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="part[@socket='left-hip' or @socket='right-hip']" mode="animate">
		<xsl:param name="state"/>
		
		
		<xsl:choose>
			<xsl:when test="$state='walking'">
				<xsl:variable name="values">
					<xsl:choose>
						<xsl:when test="@socket='right-hip'"><xsl:value-of select="-$walk-hip-front-swing-angle"/>;<xsl:value-of select="$walk-hip-back-swing-angle"/>;<xsl:value-of select="-$walk-hip-front-swing-angle"/></xsl:when>
						<xsl:otherwise><xsl:value-of select="$walk-hip-back-swing-angle"/>;<xsl:value-of select="-$walk-hip-front-swing-angle"/>;<xsl:value-of select="$walk-hip-back-swing-angle"/></xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<animateTransform attributeName="transform"
					attributeType="XML" type="rotate" values="{$values}" keyTimes="0;0.5;1"
					begin="0s" dur="1s" fill="freeze" repeatCount="indefinite"/>		
							
			</xsl:when>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="part[type//@name='humanoid-calf']" mode="animate">
		<xsl:param name="state"/>
		
		<xsl:choose>
			<xsl:when test="$state='walking'">
				<xsl:variable name="values">
					<xsl:choose>
						<xsl:when test="../@socket='right-hip'"><xsl:value-of select="-$walk-calf-front-swing-angle"/>;<xsl:value-of select="$walk-calf-back-swing-angle"/>;<xsl:value-of select="-$walk-calf-front-swing-angle"/></xsl:when>
						<xsl:otherwise><xsl:value-of select="$walk-calf-back-swing-angle"/>;<xsl:value-of select="-$walk-calf-front-swing-angle"/>;<xsl:value-of select="$walk-calf-back-swing-angle"/></xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<animateTransform attributeName="transform"
					attributeType="XML" type="rotate" values="{$values}" keyTimes="0;0.5;1"
					begin="0s" dur="1s" fill="freeze" repeatCount="indefinite"/>		
							
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	
</xsl:stylesheet>